package com.hll.javaweb.servlet.basic;

import javax.servlet.ServletConfig;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author hll
 * @create 2022-05-10 10:26
 */
@WebServlet(
    value = "/hello-config",
    initParams = {
      @WebInitParam(name = "name", value = "小明"),
      @WebInitParam(name = "pwd", value = "123456")
    })
public class HelloConfig extends HttpServlet {

  // 如果重写了init的有config形式，务必加上super.init(config)
  //  @Override
  //  public void init(ServletConfig config) throws ServletException {
  //    // super.init(config);
  //  }

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    ServletConfig config = this.getServletConfig();
    System.out.println(config.getInitParameter("name"));
    System.out.println(config.getInitParameter("pwd"));
  }
}
